<template>
  <div class="role">
    <div class="selectedRoleBox">
      <div
        class="roleBox"
        v-for="(role, index) in allRoleList"
        :key="index"
        @click="changeStatus(index)"
      >
        <img :src="role.imgUrl" alt="图片正在赶来的路上" class="imgUrl"  :class="{'active':role.isActive}" />
        <img src="../assets/success.png" class="imgSuccess" v-if="role.isActive">
        <div class="name" :class="{'active':role.isActive}"
        >{{ role.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "SingleRoleWeaponList",
  props: {
    roleList: {
      type: Object,
    },
  },
  data(){
    return{
      allRoleList:this.roleList.list
    }
  },
  methods: {
    changeStatus(index){
      this.allRoleList[index].isActive = !this.allRoleList[index].isActive
      this.$emit("changeStatus",{role:this.allRoleList[index],title:this.roleList.title})
    }
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only --> 
<style scoped lang="less">
// 定义单位数值
@roleUnit: 24px;

//selectedRoleBox
.selectedRoleBox {
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.roleBox {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 2px 1px;
  background-color: #fff;

  // 选中效果
  .imgSuccess{
    height: 60px;
    width: 60px;
    position: absolute;
  }

  // 组件角色的图片
  .imgUrl {
    height: 60px;
    width: 60px;
  }

  .imgUrl.active{
    transform: scale(0.9);
  }
  
  // 组件角色的名称
  .name {
    height: 16px;
    line-height: 16px;
    width: 60px;
    font-weight: bold;
    font-size: 0.8rem;
    text-align: center;
    color: #000;
    background-color: #FFFFFF;
  }

  .name.active{
    color: #ffffff;
    background-color: #3db39e;
  }
}
</style>
